/*
 * Copyright 2005-2013 biz-united. All rights reserved.
 * Support: http://www.biz-united.com.cn
 * License: http://www.biz-united.com.cn/?page_id=5&act=3
 */
package net.biz.service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import net.biz.Filter;
import net.biz.Page;
import net.biz.Pageable;
import net.biz.dto.OrderDTO;
import net.biz.entity.Admin;
import net.biz.entity.Cart;
import net.biz.entity.CouponCode;
import net.biz.entity.Member;
import net.biz.entity.Order;
import net.biz.entity.Order.OrderStatus;
import net.biz.entity.Order.PaymentStatus;
import net.biz.entity.Order.ShippingStatus;
import net.biz.entity.Payment;
import net.biz.entity.PaymentMethod;
import net.biz.entity.Receiver;
import net.biz.entity.Refunds;
import net.biz.entity.Returns;
import net.biz.entity.Shipping;
import net.biz.entity.ShippingMethod;

import com.home766.dto.OrderBrandCountDTO;
import com.home766.entity.Invoice;
import com.home766.entity.Shops;

/**
 * Service - 订单
 * 
 * @author BIZ Team
 * @version 3.0
 */
public interface OrderService extends BaseService<Order, Long> {

	/**
	 * 根据订单编号查找订单
	 * 
	 * @param sn
	 *            订单编号(忽略大小写)
	 * @return 若不存在则返回null
	 */
	Order findBySn(String sn);

	/**
	 * 查找订单
	 * 
	 * @param member
	 *            会员
	 * @param count
	 *            数量
	 * @param filters
	 *            筛选
	 * @param orders
	 *            排序
	 * @return 订单
	 */
	List<Order> findList(Member member, Integer count, List<Filter> filters, List<net.biz.Order> orders);

	/**
	 * 查找订单分页
	 * 
	 * @param member
	 *            会员
	 * @param pageable
	 *            分页信息
	 * @return 订单分页
	 */
	Page<Order> findPage(Member member, Pageable pageable);

	/**
	 * 查找订单分页
	 * 
	 * @param orderStatus
	 *            订单状态
	 * @param paymentStatus
	 *            支付状态
	 * @param shippingStatus
	 *            配送状态
	 * @param hasExpired
	 *            是否已过期
	 * @param pageable
	 *            分页信息
	 * @return 商品分页
	 */
	Page<Order> findPage(Shops shops, Long adminId, Date beginDate, Date endDate, Integer schemeStatus, Integer schemePaymentStatus, Integer orderType, OrderStatus orderStatus, PaymentStatus paymentStatus, ShippingStatus shippingStatus, Boolean hasExpired, Pageable pageable, String shopName, Date createDate, Long provinceId, Long cityId, Long areaId, boolean flag);
	
	/***
	 * 订单报表集合数据查询
	 * @param pageable
	 * @param shopName
	 * @param createDate
	 * @param provinceId
	 * @param cityId
	 * @param areaId
	 * @return
	 */
	List<Order> findExportList(String shopName, Date beginDate, Date endDate, Date createDate, Long provinceId, Long cityId, Long areaId);

	/**
	 * 查询订单数量
	 * 
	 * @param orderStatus
	 *            订单状态
	 * @param paymentStatus
	 *            支付状态
	 * @param shippingStatus
	 *            配送状态
	 * @param hasExpired
	 *            是否已过期
	 * @return 订单数量
	 */
	Long count(OrderStatus orderStatus, PaymentStatus paymentStatus, ShippingStatus shippingStatus, Boolean hasExpired);

	/**
	 * 查询等待支付订单数量
	 * 
	 * @param member
	 *            会员
	 * @return 等待支付订单数量
	 */
	Long waitingPaymentCount(Member member);

	/**
	 * 查询等待发货订单数量
	 * 
	 * @param member
	 *            会员
	 * @return 等待发货订单数量
	 */
	Long waitingShippingCount(Member member);

	/**
	 * 获取销售额
	 * 
	 * @param beginDate
	 *            起始日期
	 * @param endDate
	 *            结束日期
	 * @return 销售额
	 */
	BigDecimal getSalesAmount(Date beginDate, Date endDate);

	/**
	 * 获取销售量
	 * 
	 * @param beginDate
	 *            起始日期
	 * @param endDate
	 *            结束日期
	 * @return 销售量
	 */
	Integer getSalesVolume(Date beginDate, Date endDate);

	/**
	 * 释放过期订单库存
	 */
	void releaseStock();

	/**
	 * 生成订单
	 * 
	 * @param cart
	 *            购物车
	 * @param receiver
	 *            收货地址
	 * @param paymentMethod
	 *            支付方式
	 * @param shippingMethod
	 *            配送方式
	 * @param couponCode
	 *            优惠码
	 * @param isInvoice
	 *            是否开据发票
	 * @param invoiceTitle
	 *            发票抬头
	 * @param useBalance
	 *            是否使用余额
	 * @param memo
	 *            附言
	 * @return 订单
	 */
	Order build(Cart cart, Receiver receiver, PaymentMethod paymentMethod, ShippingMethod shippingMethod, CouponCode couponCode, boolean isInvoice, String invoiceTitle, boolean useBalance, String memo);
	/**
	 * 生成方案订单
	 * 
	 * @param cart
	 *            购物车
	 * @param receiver
	 *            收货地址
	 * @param paymentMethod
	 *            支付方式
	 * @param shippingMethod
	 *            配送方式
	 * @param couponCode
	 *            优惠码
	 * @param isInvoice
	 *            是否开据发票
	 * @param invoiceTitle
	 *            发票抬头
	 * @param useBalance
	 *            是否使用余额
	 * @param memo
	 *            附言
	 * @return 订单
	 */
	Order build(Member member, Receiver receiver, PaymentMethod paymentMethod, ShippingMethod shippingMethod, CouponCode couponCode, boolean isInvoice, String invoiceTitle, boolean useBalance, String memo, Integer orderType, Long schemeId, Long[] ids, Integer schemeArea, Boolean isDissipate, Boolean isTemperature, Boolean isPromote, Boolean isController, String jsonParam);

	/**
	 * 创建订单
	 * 
	 * @param cart
	 *            购物车
	 * @param receiver
	 *            收货地址
	 * @param paymentMethod
	 *            支付方式
	 * @param shippingMethod
	 *            配送方式
	 * @param couponCode
	 *            优惠码
	 * @param isInvoice
	 *            是否开据发票
	 * @param invoiceTitle
	 *            发票抬头
	 * @param useBalance
	 *            是否使用余额
	 * @param memo
	 *            附言
	 * @param operator
	 *            操作员
	 * @return 订单
	 */
	Order create(Long shopId, Integer cartType, Cart cart, Receiver receiver, PaymentMethod paymentMethod, ShippingMethod shippingMethod, CouponCode couponCode, boolean isInvoice, String invoiceTitle, boolean useBalance, String memo, Admin operator, Long schemeId, Long[] ids, Integer schemeArea, Invoice invoice, Integer invoiceType, Boolean isDissipate, Boolean isTemperature, Boolean isPromote, Boolean isController, String jsonParam);

	/**
	 * 更新订单
	 * 
	 * @param order
	 *            订单
	 * @param operator
	 *            操作员
	 */
	void update(Order order, Admin operator);

	/**
	 * 订单确认
	 * 
	 * @param order
	 *            订单
	 * @param operator
	 *            操作员
	 */
	void confirm(Order order, Admin operator);

	/**
	 * 订单完成
	 * 
	 * @param order
	 *            订单
	 * @param operator
	 *            操作员
	 */
	void complete(Order order, Admin operator);

	/**
	 * 订单取消
	 * 
	 * @param order
	 *            订单
	 * @param operator
	 *            操作员
	 */
	void cancel(Order order, Admin operator);

	/**
	 * 订单支付
	 * 
	 * @param order
	 *            订单
	 * @param payment
	 *            收款单
	 * @param operator
	 *            操作员
	 */
	void payment(Order order, Payment payment, Admin operator);

	/**
	 * 订单退款
	 * 
	 * @param order
	 *            订单
	 * @param refunds
	 *            退款单
	 * @param operator
	 *            操作员
	 */
	void refunds(Order order, Refunds refunds, Admin operator);

	/**
	 * 订单发货
	 * 
	 * @param order
	 *            订单
	 * @param shipping
	 *            发货单
	 * @param operator
	 *            操作员
	 */
	void shipping(Order order, Shipping shipping, Admin operator);

	/**
	 * 订单退货
	 * 
	 * @param order
	 *            订单
	 * @param returns
	 *            退货单
	 * @param operator
	 *            操作员
	 */
	void returns(Order order, Returns returns, Admin operator);
	
	Map<String, Object> updateSchemeStatus(Integer oldStatus, Integer newStatus, Order order, Integer staffType, Admin admin);
	
	/**
	 * 服务门店
	 * @return
	 */
	public Shops serviceShop(String sn);
	
	/**
	 * 单品 服务门店
	 * @param sn
	 * @return
	 */
	public Shops serviceShopOrder(String sn);
	
	/**
	 * 门店修改主材
	 * @param id
	 * @param edit
	 * @return
	 */
	String updateOrderItem(Long id, Long edit);

	/**
	 * @param sn 系统订单
	 * @param price 价格
	 * @param paymentOrderId  支付编号
	 * @param orderDatetime 订单时间
	 * @param payDatetime 支付时间
	 * @param admin 
	 * @param C_BANK_SERIAL_NO   银行流水号
	 * @param C_CARD_NO  缴费卡号
	 */
	int updatePaymentStatus(String sn, BigDecimal price, String paymentOrderId, String orderDatetime, String payDatetime, Admin admin, String C_BANK_SERIAL_NO, String C_CARD_NO);
	/***
	 * 单品订单报表
	 * @param schemeStatus
	 * @param orderType
	 * @param orderStatus
	 * @param paymentStatus
	 * @param shippingStatus
	 * @param hasExpired
	 * @param pageable
	 * @return
	 */
	List<OrderDTO> getOrderList(Shops shops, Long adminId, Date beginDate, Date endDate, Integer schemeStatus, Integer orderType, OrderStatus orderStatus, PaymentStatus paymentStatus, ShippingStatus shippingStatus, Boolean hasExpired, Pageable pageable);
	
	/**
	 * 统计订单中各品牌的数量
	 * @return
	 */
	List<OrderBrandCountDTO> countOrderBrandNumber();
	
	int updateServiceShop(Long id, Shops shops);
}